// RotateNozzleCommand.cpp: implementation of the RotateNozzleCommand class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "RotateNozzleCommand.h"
#include "Nozzle.h"
#include "NozzleSelector.h"
#include "NozzleGeometry.h"
#include "CommandModuleRes.h"
#include "Interact.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

RotateNozzleCommand::RotateNozzleCommand()
{

}

RotateNozzleCommand::~RotateNozzleCommand()
{

}

BOOL RotateNozzleCommand::Execute()
{
	Nozzle* pNozzle = this->GetSelectedNozzle();
	if ( pNozzle == NULL)
	{
		return FALSE;
	}

	StdString strPrompt;
	strPrompt.LoadString(COMMAND_ROTATE_BASEPOINT);
	AcGePoint3d basePoint;
	BOOL bFlag = CInteract::GetPoint(strPrompt, basePoint);
	if ( !bFlag)
	{
		return FALSE;
	}

	AcGeVector3d rotateDir;
	strPrompt.LoadString(COMMAND_ROTATE_DIR);
	bFlag = CInteract::GetDir(basePoint, strPrompt,
		 rotateDir);
	if ( !bFlag )
	{
		return FALSE;
	}

	double dAngle = 0;
	strPrompt.LoadString(COMMAND_ROTATE_ANGLE);
	bFlag = CInteract::GetReal(strPrompt, dAngle);
	if ( !bFlag )
	{
		return FALSE;
	}
	const double PI = 3.1415926535897932;
	dAngle = dAngle*PI/180;

	AcGeMatrix3d mtForm;
	mtForm.setToRotation(dAngle, rotateDir, basePoint);
	pNozzle->TransformBy(mtForm);
	
	return TRUE;
}

Nozzle* RotateNozzleCommand::GetSelectedNozzle()
{
	NozzleSelector select;
	if( select.Select())
	{
		return select.GetSelected();
	}
	else
	{
		return NULL;
	}
}
